package com.lagou.edu.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 自定义拦截器01
 */
public class MyInterceptor02 implements HandlerInterceptor {
    /**
     * 业务handler执行前
     * 一般功能: 权限校验
     * @param request
     * @param response
     * @param handler
     * @return          代表是否放行 true-放行
     */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("MyInterceptor02 preHandle...." + handler.toString());
        return true;
    }

    /**
     * 业务handler执行后跳转前
     * @param request
     * @param response
     * @param handler
     * @param modelAndView 封装了视图和数据
     */
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        System.out.println("MyInterceptor02 postHandle....");
    }

    /**
     * 业务handler跳转后
     * @param request
     * @param response
     * @param handler
     * @param ex        异常
     */
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        System.out.println("MyInterceptor02 afterCompletion....");
    }
}
